/*
 * lab14n2.c
 * Second thread example
 */

#include <stdio.h>
#include <stdlib.h> 
#include <sched.h>
#define CHILDSTACKSIZE 16384 
int x; 

  int threadtask1(void* in) { 
     int i;
     for (i=0; i<10; i++) 
        printf("   Child: i =   %d\n", i); 
  } 

int main(void) 
{ 
   // Set up stack 1 for the thread 1 
   void* child_stack1; 
   void* child_stackTop1; 
   int child_id1; 
   child_stack1 = (void *) malloc(CHILDSTACKSIZE); 
   child_stackTop1 = child_stack1 + CHILDSTACKSIZE; 

   // Set up stack 2 for the thread 2 
   void* child_stack2; 
   void* child_stackTop2; 
   int child_id2; 
   child_stack2 = (void *) malloc(CHILDSTACKSIZE); 
   child_stackTop2 = child_stack2 + CHILDSTACKSIZE; 

   x = 0; 
   printf("  Main: x = %d\n",x); 
   child_id1 = clone(threadtask1, child_stackTop1, CLONE_VM, NULL); 
   child_id2 = clone(threadtask1, child_stackTop2, CLONE_VM, NULL); 
   printf("  Main: x = %d\n",x); 
} 
